/*
 * @(#) BasGeneralForm.java  1.0  2004-4-15
 *
 * Copyright 2003 by LongTop Corporation.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 */

package com.cnc.bas.web;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;

import java.util.Date;

/**
 * User: Du bf
 * Date: 2005-3-24
 * Time: 9:22:45
 */
public class BasGeneralForm extends BasActionForm {
    private Object ltData;
    private String order = null;
    private String checkboxField = null;
    private boolean needInputInfo = false;
    private boolean needUpdateInfo = true;
    private boolean idNumber = false;
    private String IdField;

    public String getIdField() {
        return IdField;
    }

    public void setIdField(String idField) {
        IdField = idField;
    }

    public boolean isIdNumber() {
        return idNumber;
    }

    public void setIdNumber(boolean idNumber) {
        this.idNumber = idNumber;
    }

    public boolean isNeedInputInfo() {
        return needInputInfo;
    }

    public void setNeedInputInfo(boolean needInputInfo) {
        this.needInputInfo = needInputInfo;
        //this.setInputInfo();
    }

    public boolean isNeedUpdateInfo() {
        return needUpdateInfo;
    }

    public void setNeedUpdateInfo(boolean needUpdateInfo) {
        this.needUpdateInfo = needUpdateInfo;
        //this.setUpdateInfo();
    }

    public String getCheckboxField() {
        return checkboxField;
    }

    public void setCheckboxField(String checkBoxField) {
        this.checkboxField = checkBoxField;
    }


    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public Object getLtData() {
        return ltData;
    }

    public void setLtData(Object ltData) {
        this.ltData = ltData;
    }

    public void setUpdateInfo() {
        if (this.isNeedUpdateInfo() == false) return;
        try {
            PropertyUtils.setSimpleProperty(ltData, "updatetime", new Date());
            if (operator != null) PropertyUtils.setSimpleProperty(ltData, "updateuser", operator.getUserCode());
        } catch (Exception e) {

        }
    }

    public void setInputInfo() {
        if (this.isNeedInputInfo() == false) return;
        try {
            PropertyUtils.setSimpleProperty(ltData, "inputtime", new Date());
            if (operator != null) PropertyUtils.setSimpleProperty(ltData, "inputuser", operator.getUserCode());
        } catch (Exception e) {

        }
    }

    public void processCheckboxField() {
        if (this.checkboxField == null) return;
        String[] chkField = checkboxField.split(",");
        try {
            for (int i = 0; i < chkField.length; i++) {
                if ((BeanUtils.getSimpleProperty(this.ltData, chkField[i])) == null)
                    BeanUtils.setProperty(ltData, chkField[i], "F");
            }
        } catch (Exception e) {
            //
        }
    }

    public void setIdValue(Long id) {
        try {
            PropertyUtils.setSimpleProperty(ltData, this.IdField, id);
        } catch (Exception e) {
        }
    }
}


